package com.tangyuan.common.enums;

import com.tangyuan.model.UserLike;

import java.util.Optional;
import java.util.function.Consumer;

public enum Genre {

    TELEVISION(userLike -> userLike.accumulateTelevisionValue()),
    FUNNY(userLike -> userLike.accumulateFunnyValue()),
    ANIME(userLike -> userLike.accumulateAnimeValue()),
    MILITARY(userLike -> userLike.accumulateMilitaryValue()),
    GAME(userLike -> userLike.accumulateGameValue()),
    FOOD(userLike -> userLike.accumulateFoodValue()),
    VARIETY(userLike -> userLike.accumulateVarietyValue()),
    ENTERTAINMENT(userLike -> userLike.accumulateEntertainmentValue()),
    LIFE(userLike -> userLike.accumulateLifeValue()),
    SCREENING(userLike -> userLike.accumulateScreeningValue()),
    PEOPLE(userLike -> userLike.accumulatePeopleValue()),
    MUSIC(userLike -> userLike.accumulateMusicValue()),
    SQUARE(userLike -> userLike.accumulateSquareValue()),
    PETS(userLike -> userLike.accumulatePetsValue()),
    FARMERS(userLike -> userLike.accumulateFarmersValue()),
    SOCIETY(userLike -> userLike.accumulateSocietyValue()),
    SCIENCE(userLike -> userLike.accumulateScienceValue()),
    FASHION(userLike -> userLike.accumulateFashionValue()),
    AUTOMOBILE(userLike -> userLike.accumulateAutomobileValue()),
    RELATIONSHIP(userLike -> userLike.accumulateRelationshipValue()),
    CULTURE(userLike -> userLike.accumulateCultureValue()),
    TRAVEL(userLike -> userLike.accumulateTravelValue()),
    UNDERSTANDING(userLike -> userLike.accumulateUnderstandingValue()),
    BELLE(userLike -> userLike.accumulateBelleValue()),
    GUIDE(userLike -> userLike.accumulateGuideValue()),
    PAINTINGANDCALLIGRAPHY(userLike -> userLike.accumulatePaintingAndCalligraphyValue()),
    BIGSTAGE(userLike -> userLike.accumulateBigStageValue());


    private final Consumer<UserLike> action;

    Genre(Consumer<UserLike> action) {
        this.action = action;
    }

    public void apply(UserLike userLike) {
        action.accept(userLike);
    }

    public static Optional<Genre> fromString(String genreName) {
        for (Genre genre : values()) {
            if (genre.name().equalsIgnoreCase(genreName)) {
                return Optional.of(genre);
            }
        }
        return Optional.empty();
    }
}